import { lazy, Suspense } from 'react'

function LoadingSpinner() {
    return (
        <div className="flex justify-center items-center h-64">
            <div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500"></div>
            <span className="ml-2">页面加载中...</span>
        </div>
    )
}

export function lazyLoad(importFn: () => Promise<any>) {
    const Component = lazy(importFn)
    return (
        <Suspense fallback={<LoadingSpinner />} >
            <Component />
        </Suspense>
    )
}